﻿<UserControl x:Class="DeploySources.View.EnsureDataView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
			 xmlns:conv="clr-namespace:DeploySources.Converter"
             mc:Ignorable="d" 
			 d:DesignHeight="300" d:DesignWidth="400">
	<UserControl.Resources>
		<conv:BoolToHeightConverter x:Key="BoolToHeightConverter"/>
	</UserControl.Resources>
	<ScrollViewer VerticalScrollBarVisibility="Auto">
		<Grid IsEnabled="{Binding Path=IsConnected}">
			<Grid.RowDefinitions>
				<RowDefinition Height="35"/>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="35"/>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="35"/>
				<RowDefinition Height="Auto"/>
				<RowDefinition/>
			</Grid.RowDefinitions>
			<Border BorderBrush="Black" BorderThickness="0,0,0,1" Background="#3babe3">
				<Grid>
					<StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal">
						<CheckBox x:Name="FieldsExpander" Margin="5,0" Style="{StaticResource ExpanderCheckBox}"/>
						<Label VerticalAlignment="Center" Padding="8,3">Fields</Label>
					</StackPanel>
					<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
						<Button Padding="8,3" Margin="5" VerticalAlignment="Center" Command="{Binding Path=EnsureAllCommand}" CommandParameter="{Binding Path=Fields}">Ensure all</Button>
						<Button Padding="8,3" Margin="5" VerticalAlignment="Center" Command="{Binding Path=UpdateAllCommand}" CommandParameter="{Binding Path=Fields}">Update all</Button>
						<Button Padding="8,3" Margin="5" VerticalAlignment="Center" Command="{Binding Path=RebindAllCommand}" CommandParameter="{Binding Path=Fields}">Rebind all</Button>
					</StackPanel>
				</Grid>
			</Border>
			<ItemsControl Grid.Row="1" AlternationCount="2" ItemsSource="{Binding Path=Fields}" Height="{Binding ElementName=FieldsExpander, Path=IsChecked, Converter={StaticResource BoolToHeightConverter}}" >
				<ItemsControl.ItemTemplate>
					<DataTemplate>
						<Grid x:Name="FieldsGrid" Margin="0" Height="30">
							<Label HorizontalAlignment="Left" VerticalAlignment="Center"  Padding="8,3" Content="{Binding Path=Name}"/>
							<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
								<Button VerticalAlignment="Center" Margin="5,2" Padding="8,3" Command="{Binding Path=DataContext.EnsureCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}">Ensure Field</Button>
								<Button VerticalAlignment="Center" Margin="5,2" Padding="8,3" Command="{Binding Path=DataContext.UpdateCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}">Update Field</Button>
								<Button VerticalAlignment="Center" Margin="5,2" Padding="8,3" Command="{Binding Path=DataContext.RebindCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}">Rebind Field</Button>
							</StackPanel>
						</Grid>
						<DataTemplate.Triggers>
							<Trigger Property="ItemsControl.AlternationIndex" Value="0">
								<Setter Property="Background" Value="#efefef" TargetName="FieldsGrid"/>
							</Trigger>
							<Trigger Property="ItemsControl.AlternationIndex" Value="1">
								<Setter Property="Background" Value="#e0e0e0" TargetName="FieldsGrid"/>
							</Trigger>
						</DataTemplate.Triggers>
					</DataTemplate>
				</ItemsControl.ItemTemplate>
			</ItemsControl>
			<Border Grid.Row="2" BorderBrush="Black" BorderThickness="0,0,0,1" Background="#3babe3">
				<Grid >
					<StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal">
						<CheckBox x:Name="ContentTypesExpander" Margin="5,0" Style="{StaticResource ExpanderCheckBox}"/>
						<Label  Padding="8,3">Content Types</Label>
					</StackPanel>
					<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
						<Button Padding="8,3" Margin="5" VerticalAlignment="Center" Command="{Binding Path=EnsureAllCommand}" CommandParameter="{Binding Path=ContentTypes}">Ensure all</Button>
						<Button Padding="8,3" Margin="5" VerticalAlignment="Center" Command="{Binding Path=UpdateAllCommand}" CommandParameter="{Binding Path=ContentTypes}">Update all</Button>
						<Button Padding="8,3" Margin="5" VerticalAlignment="Center" Command="{Binding Path=RebindAllCommand}" CommandParameter="{Binding Path=ContentTypes}">Rebind all</Button>
					</StackPanel>
				</Grid>
			</Border>
			<ItemsControl Grid.Row="3" AlternationCount="2" ItemsSource="{Binding Path=ContentTypes}" Height="{Binding ElementName=ContentTypesExpander, Path=IsChecked, Converter={StaticResource BoolToHeightConverter}}">
				<ItemsControl.ItemTemplate>
					<DataTemplate>
						<Grid x:Name="ContentTypesGrid" Margin="0" Height="30">
							<Label HorizontalAlignment="Left" VerticalAlignment="Center"  Padding="8,3" Content="{Binding Path=Name}"/>
							<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
								<Button VerticalAlignment="Center" Margin="5,2" Padding="8,3" Command="{Binding Path=DataContext.EnsureCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}">Ensure ContentType</Button>
								<Button VerticalAlignment="Center" Margin="5,2" Padding="8,3" Command="{Binding Path=DataContext.UpdateCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}">Update ContentType</Button>
								<Button VerticalAlignment="Center" Margin="5,2" Padding="8,3" Command="{Binding Path=DataContext.RebindCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}">Rebind ContentType</Button>
							</StackPanel>
						</Grid>
						<DataTemplate.Triggers>
							<Trigger Property="ItemsControl.AlternationIndex" Value="0">
								<Setter Property="Background" Value="#efefef" TargetName="ContentTypesGrid"/>
							</Trigger>
							<Trigger Property="ItemsControl.AlternationIndex" Value="1">
								<Setter Property="Background" Value="#e0e0e0" TargetName="ContentTypesGrid"/>
							</Trigger>
						</DataTemplate.Triggers>
					</DataTemplate>
				</ItemsControl.ItemTemplate>
			</ItemsControl>
			<Border Grid.Row="4" BorderBrush="Black" BorderThickness="0,0,0,1" Background="#3babe3">
				<Grid>
					<StackPanel HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal">
						<CheckBox x:Name="ListsExpander" Margin="5,0" Style="{StaticResource ExpanderCheckBox}"/>
						<Label  Padding="8,3">Lists</Label>
					</StackPanel>
					<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
						<Button Padding="8,3" Margin="5" VerticalAlignment="Center" Command="{Binding Path=EnsureAllCommand}" CommandParameter="{Binding Path=Lists}">Ensure all</Button>
						<Button Padding="8,3" Margin="5" VerticalAlignment="Center" Command="{Binding Path=UpdateAllCommand}" CommandParameter="{Binding Path=Lists}">Update all</Button>
						<Button Padding="8,3" Margin="5" VerticalAlignment="Center" Command="{Binding Path=RebindAllCommand}" CommandParameter="{Binding Path=Lists}">Rebind all</Button>
					</StackPanel>
				</Grid>
			</Border>
			<ItemsControl Grid.Row="5" AlternationCount="2" ItemsSource="{Binding Path=Lists}" Height="{Binding ElementName=ListsExpander, Path=IsChecked, Converter={StaticResource BoolToHeightConverter}}">
				<ItemsControl.ItemTemplate>
					<DataTemplate>
						<Grid x:Name="ListsGrid" Margin="0" Height="30">
							<Label HorizontalAlignment="Left" VerticalAlignment="Center"  Padding="8,3" Content="{Binding Path=Title}"/>
							<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
								<Button VerticalAlignment="Center" Margin="5,2" Padding="8,3" Command="{Binding Path=DataContext.EnsureCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}">Ensure List</Button>
								<Button VerticalAlignment="Center" Margin="5,2" Padding="8,3" Command="{Binding Path=DataContext.UpdateCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}">Update List</Button>
								<Button VerticalAlignment="Center" Margin="5,2" Padding="8,3" Command="{Binding Path=DataContext.RebindCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}">Rebind List</Button>
							</StackPanel>
						</Grid>
						<DataTemplate.Triggers>
							<Trigger Property="ItemsControl.AlternationIndex" Value="0">
								<Setter Property="Background" Value="#efefef" TargetName="ListsGrid"/>
							</Trigger>
							<Trigger Property="ItemsControl.AlternationIndex" Value="1">
								<Setter Property="Background" Value="#e0e0e0" TargetName="ListsGrid"/>
							</Trigger>
						</DataTemplate.Triggers>
					</DataTemplate>
				</ItemsControl.ItemTemplate>
			</ItemsControl>
		</Grid>
	</ScrollViewer>
</UserControl>
